package com.wlyuan.open.domain.client.respository;

import com.wlyuan.open.application.translator.OpenApiInfoTranslator;
import com.wlyuan.open.domain.api.respository.OpenApiInfoRepository;
import com.wlyuan.open.domain.client.OpenClientId;
import com.wlyuan.open.vo.OpenApiCompanyDetailVO;
import com.wlyuan.redisson.repository.BaseCacheResolver;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import lombok.var;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.Collections;
import java.util.List;

/**
 * @author lijing
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class OpenClientApiCacheResolver implements BaseCacheResolver<OpenClientId, List<OpenApiCompanyDetailVO>> {
    private final OpenApiInfoRepository openApiInfoRepository;

    @Override
    public List<OpenApiCompanyDetailVO> resolve(OpenClientId clientId) {
        var list = openApiInfoRepository.getByClientId(clientId);
        if (CollectionUtils.isEmpty(list)) {
            return Collections.emptyList();
        }
        return OpenApiInfoTranslator.translate(list);
    }
}
